package com.study.demo.gsbean.demo1;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;

/**
 * @author: elvin
 * @time: 2019-04-17 13:58
 * @desc:
 **/
public class MyBeanFactoryAware implements BeanFactoryAware {

    private String name;

    private Man man;

    private BeanFactory beanFactory; // 自动装配时忽略注入

    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void walk(){
        if(man == null){
            man = (Man)  beanFactory.getBean("man");
        }
        System.out.println(name + " : ");
        man.walk();
    }
}
